<?php

class Order_IndexController extends Crb_Controller
{
	function preDispatch()
	{
		parent::preDispatch();
	}
	
	
	public function indexAction()
	{
	    $this->view->headScript()->appendFile('stuff/jquery/jquery.validate.js');
		if ($this->getRequest()->isPost())
		{
			$orderDAO = new Order();
			
			$params = $this->_getAllParams();
			
			$families = $params['fam'];
			$clients = array();

			for ($i = 0; $i<count($families); $i++)
			{
                if (empty($params['fam'][$i])) continue;
                
			    $clients[] = array(
			    	'firstName'=> $params['fam'][$i],
			    	'address'  => $params['add'][$i],
			    	'passport' => $params['pas'][$i],  
			     );
			}
			
			unset($params['fam']);unset($params['add']);unset($params['pas']);
			unset($params['module']);unset($params['controller']);unset($params['action']);
			
			$params['clients'] = $clients; 

			$dateArrival = new Zend_Date($params['dateArrival'], 'dd.MM.yyyy');
			$params['dateArrival'] = $dateArrival->toString('yyyy-MM-dd HH:mm:ss');

			
			$dateDeparture = new Zend_Date($params['dateDeparture'], 'dd.MM.yyyy');
			$params['dateDeparture'] = $dateDeparture->toString('yyyy-MM-dd HH:mm:ss');
			
			
			$orderDAO->create($params);
			
			$this->view->Message = "Ваша заявка принята. В ближайшее время с Вами свяжутся.";
			$this->_redirect('order/index/thanks');
		}
	}
	
	public function thanksAction()
	{
	    
	}
	
}

